package com.example.dashabi

import androidx.annotation.DrawableRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.dashabi.R


/**
 * Created by harisucici on 2021/3/5
 * Class description:
 */
@Composable
fun HomeBottomBar(current: Int, currentChanged: (Int) -> Unit) {
    Row {
        HomeBottomItem(
            Modifier
                .weight(1f)
                .clickable { currentChanged(0) },
            if (current == 0) R.drawable.ic_chat_filled else R.drawable.ic_chat_outlined,
            "主页",
            if (current == 0) Color.Blue else Color.Gray
        )
        HomeBottomItem(
            Modifier
                .weight(1f)
                .clickable { currentChanged(1) },
            if (current == 1) R.drawable.ic_contacts_filled else R.drawable.ic_contacts_outlined,
            "我的借阅",
            if (current == 1) Color.Blue else Color.Gray
        )
        HomeBottomItem(
            Modifier
                .weight(1f)
                .clickable { currentChanged(2) },
            if (current == 2) R.drawable.ic_discover_filled else R.drawable.ic_discover_outlined,
            "个人中心",
            if (current == 2) Color.Blue else Color.Gray
        )

    }
}

@Composable
fun HomeBottomItem(
    modifier: Modifier = Modifier,
    @DrawableRes iconId: Int,
    title: String,
    tint: Color
) {
    Column(
        modifier.padding(0.dp, 8.dp, 0.dp, 8.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Icon(painterResource(iconId), null, Modifier.size(24.dp), tint = tint)
        Text(title, fontSize = 11.sp, color = tint)
    }
}

